/* test */
function read_overview(url_read, domain_used, bioventurist_domain, id){		
	var q  = '{"query":[{"id":"'+id+'","name":null,"type":"'+bioventurist_domain+'biomolecule"}]}';
	perform_freebase_read(
		url_read,
		q,
		function (msg) {
			var biomolecule = null;
			biomolecule = msg.result[0];
			if (!biomolecule) return;
			
			var topic_domain = '/user/bioventurist/default_domain/biomolecule';
			jsonp_totalblurb_freebase(domain_used, name, topic_domain, 5000,
			function(m){
				$("#thumb").attr('src','http://'+domain_used+'/api/trans/image_thumb'+m.result[0].image.id);
			},
			function(m){
				$("#description").append($('<span>'+m.result.body+'</span>'));
			},
			function(m){});
			
		},
		function(m){}
	);
}
function read_therapeutics(url_read, domain_used, bioventurist_domain, id){	
	var q = '{"query":[{"biomolecule_or_target":"'+name+'","type":"'+bioventurist_domain+'bv_therapeutic","name":null}]}';
	perform_freebase_read(
		url_read,
		q,
		function (msg) {
			var therapeutic = null;
			therapeutic = msg.result[0];
	        if (!therapeutic) return;
			therapeutics = msg.result;
	        if(therapeutics.length > 0) {
	        	
	        	var h = '<h2>Therapeutics that Target '+name+'</h2>';
	        	h = $(h)
				$("#therapeutics_header").append(h); 
	        	
	        	
	        	var therData = new google.visualization.DataTable();
	    		therData.addColumn('string', 'Therapeutic');
	    		therData.addColumn('string', 'Phase of Development');
	    		therData.addColumn('string', 'Developed by');
	    		therData.addColumn('string', 'Overview');
	    		therData.addColumn('string', '');
	 			therData.addRows(therapeutics.length);
  			 	var dTable = new google.visualization.Table(document.getElementById('therapeutics_div'));      			
  		 		var verboses = Array(therapeutics.length);
 				for (var i=0;i<therapeutics.length;i=i+1) {	 	
 					verboses[i] = false;
 				}
 				var view = new google.visualization.DataView(therData);
  				view.setColumns([0,1,2,3]); 
  				var topic_domain = '/user/bioventurist/default_domain/bv_therapeutic';
	 			
				for (var i in therapeutics) {
					var therapeuticName = therapeutics[i].name;
					var theraLink = '<a href="/therapeutic/' + therapeuticName + '">' + therapeuticName + '</a>';
												
					therData.setCell(parseFloat(i), 0, theraLink);
					x(i,3,4,therData, view, therapeuticName, topic_domain, domain_used,  dTable, 500, 100);
					dTable.draw(view, {allowHtml: true});	

					var qProduct = '{"query":[{"developed_by":null,"name":"'+therapeuticName+'","type":"/user/bioventurist/default_domain/product"}]}';	
					perform_freebase_read(
						url_read,
						qProduct,
						function (msgProduct) {
							var product = null;
							product = msgProduct.result[0];
					        if (!product) return;
							products = msgProduct.result;
					        if(products.length > 0) {
					        	var devBy = products[0].developed_by;
//				        		therData.setCell(parseFloat(i), 2,devBy);							
							}			
	
						},
						function(m){}
					);
					

				
				}
				dTable.draw(therData, {allowHtml: true});		
			
				
						
			}
			 
		},
		function(m){}
	);
}
// Need to figure out how to get this to bioventurist.js
function x(i,j,hiddenj, t,v,name, topic, freebaseDomain, table, maxlength, stublength) {
	
	jsonp_totalblurb_freebase(freebaseDomain, name, topic, maxlength, 
		function(m){
		},
		function(m){
			t.setCell(parseFloat(i), j, m.result.body.substring(0,stublength)+'...');
			t.setCell(parseFloat(i), hiddenj, m.result.body+'...');
   			table.draw(v, {allowHtml: true});	
		},
		function(m){} 
	);
}
